﻿// ===============================================================================
//  Copyright © ymind.net. All rights reserved .
//  官方网站：http://ymind.net/
//  版权所有：彦铭工作室 老陈出品
// ===============================================================================

using System;

namespace Lcsoft.UrlRewriter.Conditions
{
	/// <summary>
	/// 表示给定先决条件的负匹配。
	/// </summary>
	public sealed class NegativeCondition : IRewriteCondition
	{
		private readonly IRewriteCondition _chainedCondition;

		/// <summary>
		/// 初始化 <see cref="NegativeCondition"/> 类的新实例。
		/// </summary>
		/// <param name="chainedCondition">先决条件。</param>
		public NegativeCondition(IRewriteCondition chainedCondition)
		{
			if (chainedCondition == null) throw new ArgumentNullException("chainedCondition");

			this._chainedCondition = chainedCondition;
		}

		#region IRewriteCondition Members

		/// <summary>
		/// 判断条件是否满足。
		/// </summary>
		/// <param name="context"><see cref="RewriteContext"/> 对象的实例。</param>
		/// <returns>如果条件满足则返回 true，否则返回 false。</returns>
		public bool IsMatch(RewriteContext context)
		{
			if (context == null) throw new ArgumentNullException("context");

			return !this._chainedCondition.IsMatch(context);
		}

		#endregion
	}
}
